package com.cloudsigns.factorymanager2.project.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.ILoginView;
import com.cloudsigns.factorymanager2.engineering.model.ILoginModel;
import com.cloudsigns.factorymanager2.engineering.model.LoginModel;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.iview.IAddEngineeringInstallationOrderView;
import com.cloudsigns.factorymanager2.project.model.AddEngineeringInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddEngineeringInstallationOrderModel;

import java.util.List;

/**
 * Created by tony on 2018/3/10.
 */

public class AddEngineeringInstallationOrderPresenter {
    private IAddEngineeringInstallationOrderView view;
    private IAddEngineeringInstallationOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddEngineeringInstallationOrderPresenter(IAddEngineeringInstallationOrderView view) {
        this.view = view;
        this.model = new AddEngineeringInstallationOrderModel();
    }

    public void addEngineeringInatallationOrder() {

        model.addEngineeringInatallationOrder(view.getCompleteDate(),view.getEngineeringAddress(), view.getEngineeringName(),view.getLat(),view.getLon(),view.getPicUrl(), view.getProjectName(), view.getProductBeans(), new AddEngineeringInstallationOrderModel.OnAddEngineeringInstallationOrderListener() {

            @Override
            public void success(final String projectId) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addEngineeringInstallatonOrderSuccess(projectId);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }

}
